var addRole={
    switchInt:function () {
        $('.switch input').bootstrapSwitch();
        $(".switch input").bootstrapSwitch('state', true);
    },
    isRoleName:function(){
        if(null == $("#roleName").val() || "" == $("#roleName").val()){
            $("#ts").html("角色名称不能为空");
            return;
        }
        $.post(
            application.contextPath+"/role/queryRoleNameByText",
            {roleName:$("#roleName").val()},
            function (res){
                 if('0'!=res.data){
                     $("#ts").html("角色名称已存在");
                 }
             }
        )
    },
    commitAdd:function (form) {
        var data = {};
        data.roleName=$("#roleName").val();
        data.desc=$("#roleArea").val();
        if($('.switch input').bootstrapSwitch('state') ==true){
            data.state="1";
        }else {
            data.state="2";
        }
        $.ajax({
            url: application.contextPath+"/role/addRole",
            type:"POST",
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            data:JSON.stringify({parmsMap:data}),
            success:function (res) {
                var tit="角色创建成功";
                if("1" !=res.data){
                    tit="角色创建失败"
                }
                layer.close(layer.index);
                layer.msg(tit,{icon:1,title:'新增提示',btn:['是','否'],yes(){
                        $('#tableList').bootstrapTable('refresh');
                        layer.close(layer.index);
                    },function(){
                        // layer.close(layer.index);
                    }});
            }
        });
        return false;
    },
    clearSpan:function () {
        $("#ts").html("");
    }
};

$(document).ready(function(){
    addRole.switchInt();
    $("#clo").click(function(){
        layer.close(layer.index);
    })
});